﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ZedGraph;
using System.Drawing;
using C1.Win.C1Chart;
using Microsoft.Office.Interop.Excel;
using System.IO;

namespace LED_Tester
{
    class ClassPrint
    {
        #region 极地坐标

        int step = 250;

        double yMin = 0;
        double yMax = 7000;

        private void initailize(ZedGraphControl zedPolar)
        {
            #region 初始化图像

            zedPolar.GraphPane.Fill = new Fill(Color.White);// fill background by color black
            zedPolar.GraphPane.Chart.Fill.Type = FillType.None;
            zedPolar.GraphPane.Title.Text = "";
            zedPolar.GraphPane.XAxis.Title.Text = "";
            zedPolar.GraphPane.YAxis.Title.Text = "";

            zedPolar.GraphPane.YAxis.Color = Color.White;
            zedPolar.GraphPane.XAxis.Color = Color.White;
            zedPolar.GraphPane.Y2Axis.Color = Color.White;
            zedPolar.GraphPane.X2Axis.Color = Color.White;

            zedPolar.GraphPane.XAxis.IsVisible = false;
            zedPolar.GraphPane.YAxis.IsVisible = false;
            zedPolar.GraphPane.X2Axis.IsVisible = false;
            zedPolar.GraphPane.Y2Axis.IsVisible = false;
            zedPolar.GraphPane.YAxis.MajorGrid.IsZeroLine = false;
            zedPolar.GraphPane.Chart.Border.IsVisible = false;

            zedPolar.GraphPane.XAxis.Scale.MajorStepAuto = false;
            zedPolar.GraphPane.YAxis.Scale.MajorStepAuto = false;
            zedPolar.GraphPane.XAxis.Scale.Min = -1100;
            zedPolar.GraphPane.XAxis.Scale.Max = 1100;
            zedPolar.GraphPane.YAxis.Scale.Min = -350;
            zedPolar.GraphPane.YAxis.Scale.Max = 1350;
            zedPolar.GraphPane.XAxis.Scale.MajorStep = 250;
            zedPolar.GraphPane.YAxis.Scale.MajorStep = 250;
            zedPolar.GraphPane.YAxis.Scale.IsSkipFirstLabel = true;
            zedPolar.GraphPane.YAxis.Scale.IsReverse = true;// reverse
            zedPolar.GraphPane.XAxis.Scale.IsReverse = true;

            zedPolar.IsShowContextMenu = false;
            zedPolar.IsEnableHZoom = false;
            zedPolar.IsEnableVZoom = false;

            #endregion

            #region 画边框

            PointPairList pplSouth = new PointPairList();
            pplSouth.Add(-4 * step, 5 * step);
            pplSouth.Add(4 * step, 5 * step);
            LineItem litSouth = zedPolar.GraphPane.AddCurve("", pplSouth, Color.Black, SymbolType.None);
            litSouth.Line.Width = 2.0f;

            PointPairList pplNorth = new PointPairList();
            pplNorth.Add(-4 * step, -step);
            pplNorth.Add(4 * step, -step);
            LineItem litNorth = zedPolar.GraphPane.AddCurve("", pplNorth, Color.Black, SymbolType.None);
            litNorth.Line.Width = 2.0f;

            PointPairList pplWest = new PointPairList();
            pplWest.Add(4 * step, -step);
            pplWest.Add(4 * step, 5 * step);
            LineItem litWest = zedPolar.GraphPane.AddCurve("", pplWest, Color.Black, SymbolType.None);
            litWest.Line.Width = 2.0f;

            PointPairList pplEast = new PointPairList();
            pplEast.Add(-4 * step, -step);
            pplEast.Add(-4 * step, 5 * step);
            LineItem iltEast = zedPolar.GraphPane.AddCurve("", pplEast, Color.Black, SymbolType.None);
            iltEast.Line.Width = 2.0f;

            PointPairList pplXAsxi = new PointPairList();
            pplXAsxi.Add(-4 * step, 0);
            pplXAsxi.Add(4 * step, 0);
            LineItem litXAsxi = zedPolar.GraphPane.AddCurve("", pplXAsxi, Color.Black, SymbolType.None);

            PointPairList pplYAsxi = new PointPairList();
            pplYAsxi.Add(0, -step);
            pplYAsxi.Add(0, 5 * step);
            LineItem litYAxi = zedPolar.GraphPane.AddCurve("", pplYAsxi, Color.Black, SymbolType.None);

            #endregion

            #region 画圆弧

            double x, y;

            PointPairList pplArc0 = new PointPairList();
            PointPairList pplArc1 = new PointPairList();
            PointPairList pplArc2 = new PointPairList();
            PointPairList pplArc3 = new PointPairList();
            PointPairList pplArc4 = new PointPairList();
            PointPairList pplArc5 = new PointPairList();
            for (int i = -90; i < 270; i++)
            {
                x = step * Math.Cos(Math.PI * i / 180);
                y = step * Math.Sin(Math.PI * i / 180);
                pplArc0.Add(x, y);

                if (2 * y > -step * 1.01f)
                {
                    pplArc1.Add(2 * x, 2 * y);
                }
                if (3 * y >= -step * 1.026051f)
                {
                    pplArc2.Add(3 * x, 3 * y);
                }
                if (4 * y >= -step * 1.035276f)
                {
                    pplArc3.Add(4 * x, 4 * y);
                }
                if (5 * x < -4 * step || 5 * x > 4 * step || 5 * y < -step)
                {
                    continue;
                }
                pplArc4.Add(5 * x, 5 * y);
                if (6 * x < -4 * step || 6 * x > 4 * step || 6 * y < -step || 6 * y > 5 * step + 8.0057f)
                {
                    continue;
                }
                pplArc5.Add(6 * x, 6 * y);
            }
            LineItem litArc0 = zedPolar.GraphPane.AddCurve("", pplArc0, Color.Black, SymbolType.None);
            LineItem litArc1 = zedPolar.GraphPane.AddCurve("", pplArc1, Color.Black, SymbolType.None);
            LineItem litArc2 = zedPolar.GraphPane.AddCurve("", pplArc2, Color.Black, SymbolType.None);
            LineItem litArc3 = zedPolar.GraphPane.AddCurve("", pplArc3, Color.Black, SymbolType.None);
            LineItem litArc4 = zedPolar.GraphPane.AddCurve("", pplArc4, Color.Black, SymbolType.None);
            LineItem litArc5 = zedPolar.GraphPane.AddCurve("", pplArc5, Color.Black, SymbolType.None);

            #endregion

            #region 画射线

            PointPairList pplCurve0 = new PointPairList();   //15°
            PointPairList pplCurve1 = new PointPairList();  //30°
            PointPairList pplCurve2 = new PointPairList();  //45°
            PointPairList pplCurve3 = new PointPairList();  //60°
            PointPairList pplCurve4 = new PointPairList();  //75°
            PointPairList pplCurve5 = new PointPairList();  //-15°
            PointPairList pplCurve6 = new PointPairList();  //-30°
            PointPairList pplCurve7 = new PointPairList();  //-45°
            PointPairList pplCurve8 = new PointPairList();  //-60°
            PointPairList pplCurve9 = new PointPairList();  //-75°
            PointPairList pplCurve10 = new PointPairList();  //105°
            PointPairList pplCurve11 = new PointPairList();  //120°
            PointPairList pplCurve12 = new PointPairList();  //135°
            PointPairList pplCurve13 = new PointPairList();  //150°
            PointPairList pplCurve14 = new PointPairList();  //165°
            PointPairList pplCurve15 = new PointPairList();  //-105°
            PointPairList pplCurve16 = new PointPairList();  //-120°
            PointPairList pplCurve17 = new PointPairList();  //-135°
            PointPairList pplCurve18 = new PointPairList();  //-150°
            PointPairList pplCurve19 = new PointPairList();  //-165°

            double[,] intersection = new double[14, 2];
            // 15°
            for (y = step * Math.Cos(Math.PI / 180 * 15); y <= 5 * step; y += 1)
            {
                x = y * Math.Tan(Math.PI / 180 * 15);
                if (y > 5 * step - 1)
                {
                    intersection[0, 0] = x;
                    intersection[0, 1] = y;
                }
                pplCurve0.Add(x, y);
            }
            // 30°
            for (y = step * Math.Cos(Math.PI / 6); y <= 5 * step; y += 1)
            {
                x = y * Math.Tan(Math.PI / 6);
                if (y > 5 * step - 1)
                {
                    intersection[1, 0] = x;
                    intersection[1, 1] = y;
                }
                pplCurve1.Add(x, y);
            }
            // 45°
            for (y = step * Math.Cos(Math.PI / 4); y <= 4 * step; y += 1)
            {
                x = y * Math.Tan(Math.PI / 4);
                if (x > 4 * step - 1)
                {
                    intersection[2, 0] = x;
                    intersection[2, 1] = y;
                }
                pplCurve2.Add(x, y);
            }
            // 60°
            for (y = step * Math.Cos(Math.PI / 3); y <= 4 * step / Math.Sqrt(3); y += 1)
            {
                x = y * Math.Tan(Math.PI / 3);
                if (x > 4 * step - 1)
                {
                    intersection[3, 0] = x;
                    intersection[3, 1] = y;
                }
                pplCurve3.Add(x, y);
            }
            // 75°
            for (y = step * Math.Cos(Math.PI / 180 * 75); y <= 4 * step / (2 + Math.Sqrt(3)); y += 1)
            {
                x = y * Math.Tan(Math.PI / 180 * 75);
                if (x > 4 * step - 1)
                {
                    intersection[4, 0] = x;
                    intersection[4, 1] = y;
                }
                pplCurve4.Add(x, y);
            }
            // -15°
            for (y = step * Math.Cos(Math.PI / 180 * 15); y <= 5 * step; y += 1)
            {
                x = y * Math.Tan(-Math.PI / 180 * 15);
                if (y > 5 * step - 1)
                {
                    intersection[5, 0] = x;
                    intersection[5, 1] = y;
                }
                pplCurve5.Add(x, y);
            }
            // -30°
            for (y = step * Math.Cos(Math.PI / 6); y <= 5 * step; y += 1)
            {
                x = y * Math.Tan(-Math.PI / 6);
                if (y > 5 * step - 1)
                {
                    intersection[6, 0] = x;
                    intersection[6, 1] = y;
                }
                pplCurve6.Add(x, y);
            }
            // -45°
            for (y = step * Math.Cos(Math.PI / 4); y <= 4 * step; y += 1)
            {
                x = y * Math.Tan(-Math.PI / 4);
                if (x < -4 * step + 1)
                {
                    intersection[7, 0] = x;
                    intersection[7, 1] = y;
                }
                pplCurve7.Add(x, y);
            }
            // -60°
            for (y = step * Math.Cos(Math.PI / 3); y <= 4 * step / Math.Sqrt(3); y += 1)
            {
                x = y * Math.Tan(-Math.PI / 3);
                if (x < -4 * step + 1)
                {
                    intersection[8, 0] = x;
                    intersection[8, 1] = y;
                }
                pplCurve8.Add(x, y);
            }
            // -75°
            for (y = step * Math.Cos(Math.PI / 180 * 75); y <= 4 * step / (2 + Math.Sqrt(3)); y += 1)
            {
                x = y * Math.Tan(-Math.PI / 180 * 75);
                if (x < -4 * step + 1)
                {
                    intersection[9, 0] = x;
                    intersection[9, 1] = y;
                }
                pplCurve9.Add(x, y);
            }
            // 105°
            for (x = step * Math.Cos(Math.PI / 180 * 15); x <= step / (2 - Math.Sqrt(3)); x += 1)
            {
                y = -x * Math.Tan(Math.PI / 180 * 15);
                if (y < -step + 1)
                {
                    intersection[10, 0] = x;
                    intersection[10, 1] = y;
                }
                pplCurve10.Add(x, y);
            }
            // 120°
            for (x = step * Math.Cos(Math.PI / 6); x <= step * Math.Sqrt(3); x += 1)
            {
                y = -x * Math.Tan(Math.PI / 6);
                if (y < -step + 1)
                {
                    intersection[11, 0] = x;
                    intersection[11, 1] = y;
                }
                pplCurve11.Add(x, y);
            }
            // 135°
            for (x = step * Math.Cos(Math.PI / 4); x <= step; x += 1)
            {
                y = -x * Math.Tan(Math.PI / 4);
                pplCurve12.Add(x, y);
            }
            // 150°
            for (x = step * Math.Cos(Math.PI / 3); x <= step / Math.Sqrt(3); x += 1)
            {
                y = -x * Math.Tan(Math.PI / 3);
                pplCurve13.Add(x, y);
            }
            // 165°
            for (x = step * Math.Cos(Math.PI / 180 * 75); x <= step / (2 + Math.Sqrt(3)); x += 1)
            {
                y = -x * Math.Tan(Math.PI / 180 * 75);
                pplCurve14.Add(x, y);
            }
            // -105°
            for (x = -step * Math.Cos(Math.PI / 180 * 15); x >= -step / (2 - Math.Sqrt(3)); x -= 1)
            {
                y = x * Math.Tan(Math.PI / 180 * 15);
                if (y < -step + 1)
                {
                    intersection[12, 0] = x;
                    intersection[12, 1] = y;
                }
                pplCurve15.Add(x, y);
            }
            // -120°
            for (x = -step * Math.Cos(Math.PI / 6); x >= -step * Math.Sqrt(3); x -= 1)
            {
                y = x * Math.Tan(Math.PI / 6);
                if (y < -step + 1)
                {
                    intersection[13, 0] = x;
                    intersection[13, 1] = y;
                }
                pplCurve16.Add(x, y);
            }
            // -135°
            for (x = -step * Math.Cos(Math.PI / 4); x >= -step; x -= 1)
            {
                y = x * Math.Tan(Math.PI / 4);
                pplCurve17.Add(x, y);
            }
            // -150°
            for (x = -step * Math.Cos(Math.PI / 3); x >= -step / Math.Sqrt(3); x -= 1)
            {
                y = x * Math.Tan(Math.PI / 3);
                pplCurve18.Add(x, y);
            }
            // -165°
            for (x = -step * Math.Cos(Math.PI / 180 * 75); x >= -step / (2 + Math.Sqrt(3)); x -= 1)
            {
                y = x * Math.Tan(Math.PI / 180 * 75);
                pplCurve19.Add(x, y);
            }

            LineItem litCurve0 = zedPolar.GraphPane.AddCurve("", pplCurve0, Color.Black, SymbolType.None);
            LineItem litCurve1 = zedPolar.GraphPane.AddCurve("", pplCurve1, Color.Black, SymbolType.None);
            LineItem litCurve2 = zedPolar.GraphPane.AddCurve("", pplCurve2, Color.Black, SymbolType.None);
            LineItem litCurve3 = zedPolar.GraphPane.AddCurve("", pplCurve3, Color.Black, SymbolType.None);
            LineItem litCurve4 = zedPolar.GraphPane.AddCurve("", pplCurve4, Color.Black, SymbolType.None);
            LineItem litCurve5 = zedPolar.GraphPane.AddCurve("", pplCurve5, Color.Black, SymbolType.None);
            LineItem litCurve6 = zedPolar.GraphPane.AddCurve("", pplCurve6, Color.Black, SymbolType.None);
            LineItem litCurve7 = zedPolar.GraphPane.AddCurve("", pplCurve7, Color.Black, SymbolType.None);
            LineItem litCurve8 = zedPolar.GraphPane.AddCurve("", pplCurve8, Color.Black, SymbolType.None);
            LineItem litCurve9 = zedPolar.GraphPane.AddCurve("", pplCurve9, Color.Black, SymbolType.None);
            LineItem litCurve10 = zedPolar.GraphPane.AddCurve("", pplCurve10, Color.Black, SymbolType.None);
            LineItem litCurve11 = zedPolar.GraphPane.AddCurve("", pplCurve11, Color.Black, SymbolType.None);
            LineItem litCurve12 = zedPolar.GraphPane.AddCurve("", pplCurve12, Color.Black, SymbolType.None);
            LineItem litCurve13 = zedPolar.GraphPane.AddCurve("", pplCurve13, Color.Black, SymbolType.None);
            LineItem litCurve14 = zedPolar.GraphPane.AddCurve("", pplCurve14, Color.Black, SymbolType.None);
            LineItem litCurve15 = zedPolar.GraphPane.AddCurve("", pplCurve15, Color.Black, SymbolType.None);
            LineItem litCurve16 = zedPolar.GraphPane.AddCurve("", pplCurve16, Color.Black, SymbolType.None);
            LineItem litCurve17 = zedPolar.GraphPane.AddCurve("", pplCurve17, Color.Black, SymbolType.None);
            LineItem litCurve18 = zedPolar.GraphPane.AddCurve("", pplCurve18, Color.Black, SymbolType.None);
            LineItem litCurve19 = zedPolar.GraphPane.AddCurve("", pplCurve19, Color.Black, SymbolType.None);

            #endregion

            #region 画标注

            TextObj txt0 = new TextObj("-90", 4 * step + 100, 0 + 10, CoordType.AxisXYScale, AlignH.Left, AlignV.Top);
            TextObj txt1 = new TextObj("90", -4 * step - 80, 0 + 10, CoordType.AxisXYScale, AlignH.Right, AlignV.Top);
            TextObj txt2 = new TextObj("0", 0, 5 * step + 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            TextObj txt3 = new TextObj("-15", intersection[0, 0], intersection[0, 1] + 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            TextObj txt4 = new TextObj("-30", intersection[1, 0], intersection[1, 1] + 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            TextObj txt5 = new TextObj("-45", intersection[2, 0] + 100, intersection[2, 1] + 20, CoordType.AxisXYScale, AlignH.Left, AlignV.Top);
            TextObj txt6 = new TextObj("-60", intersection[3, 0] + 100, intersection[3, 1] + 20, CoordType.AxisXYScale, AlignH.Left, AlignV.Top);
            TextObj txt7 = new TextObj("-75", intersection[4, 0] + 100, intersection[4, 1] + 20, CoordType.AxisXYScale, AlignH.Left, AlignV.Top);
            TextObj txt8 = new TextObj("15", intersection[5, 0], intersection[5, 1] + 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            TextObj txt9 = new TextObj("30", intersection[6, 0], intersection[6, 1] + 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
            TextObj txt10 = new TextObj("45", intersection[7, 0] - 80, intersection[7, 1] + 20, CoordType.AxisXYScale, AlignH.Right, AlignV.Top);
            TextObj txt11 = new TextObj("60", intersection[8, 0] - 80, intersection[8, 1] + 20, CoordType.AxisXYScale, AlignH.Right, AlignV.Top);
            TextObj txt12 = new TextObj("75", intersection[9, 0] - 80, intersection[9, 1] + 20, CoordType.AxisXYScale, AlignH.Right, AlignV.Top);
            TextObj txt13 = new TextObj("-105", intersection[10, 0], intersection[10, 1] - 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom);
            TextObj txt14 = new TextObj("-120", intersection[11, 0], intersection[11, 1] - 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom);
            TextObj txt15 = new TextObj("105", intersection[12, 0], intersection[12, 1] - 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom);
            TextObj txt16 = new TextObj("120", intersection[13, 0], intersection[13, 1] - 20, CoordType.AxisXYScale, AlignH.Center, AlignV.Bottom);

            txt0.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt0.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt0.FontSpec.FontColor = Color.Black;
            txt1.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt1.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt1.FontSpec.FontColor = Color.Black;
            txt2.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt2.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt2.FontSpec.FontColor = Color.Black;
            txt3.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt3.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt3.FontSpec.FontColor = Color.Black;
            txt4.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt4.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt4.FontSpec.FontColor = Color.Black;
            txt5.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt5.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt5.FontSpec.FontColor = Color.Black;
            txt6.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt6.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt6.FontSpec.FontColor = Color.Black;
            txt7.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt7.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt7.FontSpec.FontColor = Color.Black;
            txt8.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt8.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt8.FontSpec.FontColor = Color.Black;
            txt9.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt9.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt9.FontSpec.FontColor = Color.Black;
            txt10.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt10.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt10.FontSpec.FontColor = Color.Black;
            txt11.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt11.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt11.FontSpec.FontColor = Color.Black;
            txt12.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt12.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt12.FontSpec.FontColor = Color.Black;
            txt13.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt13.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt13.FontSpec.FontColor = Color.Black;
            txt14.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt14.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt14.FontSpec.FontColor = Color.Black;
            txt15.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt15.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt15.FontSpec.FontColor = Color.Black;
            txt16.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txt16.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
            txt16.FontSpec.FontColor = Color.Black;

            zedPolar.GraphPane.GraphObjList.Add(txt0);
            zedPolar.GraphPane.GraphObjList.Add(txt1);
            zedPolar.GraphPane.GraphObjList.Add(txt2);
            zedPolar.GraphPane.GraphObjList.Add(txt3);
            zedPolar.GraphPane.GraphObjList.Add(txt4);
            zedPolar.GraphPane.GraphObjList.Add(txt5);
            zedPolar.GraphPane.GraphObjList.Add(txt6);
            zedPolar.GraphPane.GraphObjList.Add(txt7);
            zedPolar.GraphPane.GraphObjList.Add(txt8);
            zedPolar.GraphPane.GraphObjList.Add(txt9);
            zedPolar.GraphPane.GraphObjList.Add(txt10);
            zedPolar.GraphPane.GraphObjList.Add(txt11);
            zedPolar.GraphPane.GraphObjList.Add(txt12);
            zedPolar.GraphPane.GraphObjList.Add(txt13);
            zedPolar.GraphPane.GraphObjList.Add(txt14);
            zedPolar.GraphPane.GraphObjList.Add(txt15);
            zedPolar.GraphPane.GraphObjList.Add(txt16);

            #endregion
        }

        private double[,] angToReg(double gammaSample, double gammaRange, double[] data)
        {
            double[,] reg = new double[2, data.Length];
            int i = 0;
            foreach (double value in data)
            {
                double degree = Math.PI * (-gammaRange + i * gammaSample + 90) / 180;
                double length = (value - yMin) * 1000 / (yMax - yMin);
                reg[0, i] = length * Math.Cos(degree);
                reg[1, i] = length * Math.Sin(degree);
                i++;
            }
            return reg;
        }

        private void setAxsi(ZedGraphControl zedPolar, double[] data)
        {
            yMin = data.Min();
            yMax = data.Max();

            if (yMax <= 0)
            {
                yMin = 0;
                yMax = 7000;
            }

            TextObj txtStepMin = new TextObj(yMin.ToString("#0"), 0, 0 + 10, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);

            txtStepMin.FontSpec.FontColor = Color.Black;
            txtStepMin.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
            txtStepMin.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);

            if (zedPolar.GraphPane.GraphObjList.Count < 18)
                zedPolar.GraphPane.GraphObjList.Add(txtStepMin);
            else
                zedPolar.GraphPane.GraphObjList[17] = txtStepMin;

            for (int i = 1; i < 5; i++)
            {
                TextObj txtStep = new TextObj((yMin + (yMax - yMin) * i / 4).ToString("#0"), 0, i * step, CoordType.AxisXYScale, AlignH.Center, AlignV.Top);
                txtStep.FontSpec.Border = new ZedGraph.Border(false, Color.Black, 0.1f);
                txtStep.FontSpec.Fill = new Fill(Color.Black, new SolidBrush(Color.Black), FillType.None);
                txtStep.FontSpec.FontColor = Color.Black;

                if (zedPolar.GraphPane.GraphObjList.Count < 18 + i)
                {
                    zedPolar.GraphPane.GraphObjList.Add(txtStep);
                }
                else
                {
                    zedPolar.GraphPane.GraphObjList[17 + i] = txtStep;
                }
            }

            zedPolar.Refresh();
        }

        public Image PrintPolar(double gammaSample, double gammaRange, double[] data)
        {
            ZedGraph.ZedGraphControl zedPolar = new ZedGraphControl();

            initailize(zedPolar);

            zedPolar.Width = 1100;
            zedPolar.Height = 600;

            setAxsi(zedPolar, data);

            double[,] temp = angToReg(gammaSample, gammaRange, data);

            PointPairList pplPoint = new PointPairList();

            pplPoint.Clear();

            for (int i = 0; i < temp.Length / 2; i++)
            {
                pplPoint.Add(temp[0, i], temp[1, i]);
            }

            LineItem litCurve = zedPolar.GraphPane.AddCurve("", pplPoint, Color.Red, SymbolType.None);
            zedPolar.Refresh();

            return zedPolar.GetImage();
        }

        #endregion

        #region 直角坐标

        public Image PrintRadiant2D(double gammaSample, double gammaRange, double[] data)
        {
            frmR2 frm_R2 = new frmR2();

            C1Chart chart2D = frm_R2.Return();

            chart2D.Width = 300;
            chart2D.Height = 500;

            chart2D.BackColor = Color.Black;
            chart2D.Style.BackColor = Color.White;
            chart2D.ChartArea.Style.ForeColor = Color.White;
            chart2D.ChartArea.PlotArea.BackColor = Color.White;
            chart2D.ChartArea.PlotArea.ForeColor = Color.White;
            chart2D.ChartArea.Style.BackColor = Color.White;
            chart2D.ChartArea.AxisX.ForeColor = Color.Black;
            chart2D.ChartArea.AxisY.ForeColor = Color.Black;
            chart2D.ChartArea.AxisX.GridMajor.Color = Color.Black;
            chart2D.ChartArea.AxisY.GridMajor.Color = Color.Black;

            chart2D.ChartGroups.ChartGroupsCollection[0].ChartData[0].PointData.Clear();
            chart2D.ChartGroups.ChartGroupsCollection[0].ChartData[0].LineStyle.Color = Color.Red;

            int length = (int)(2 * gammaRange / gammaSample + 1);

            for (int i = 0; i < length; i++)
            {
                chart2D.ChartGroups[0].ChartData.SeriesList[0].X.Add(-1 * gammaRange + i * gammaSample);
                chart2D.ChartGroups[0].ChartData.SeriesList[0].Y.Add(data[i]);
            }

            chart2D.ChartArea.AxisX.Max = gammaRange;
            chart2D.ChartArea.AxisX.Min = -1 * gammaRange;

            return chart2D.GetImage();
        }

        public Image PrintLuminous2D(double gammaSample, double gammaRange, double[] data)
        {
            frmL2 frm_L2 = new frmL2();
            C1Chart chart2D = frm_L2.Return();

            chart2D.BackColor = Color.Black;
            chart2D.Style.BackColor = Color.White;
            chart2D.ChartArea.Style.ForeColor = Color.White;
            chart2D.ChartArea.PlotArea.BackColor = Color.White;
            chart2D.ChartArea.PlotArea.ForeColor = Color.White;
            chart2D.ChartArea.Style.BackColor = Color.White;
            chart2D.ChartArea.AxisX.ForeColor = Color.Black;
            chart2D.ChartArea.AxisY.ForeColor = Color.Black;
            chart2D.ChartArea.AxisX.GridMajor.Color = Color.Black;
            chart2D.ChartArea.AxisY.GridMajor.Color = Color.Black;

            chart2D.ChartGroups.ChartGroupsCollection[0].ChartData[0].PointData.Clear();
            chart2D.ChartGroups.ChartGroupsCollection[0].ChartData[0].LineStyle.Color = Color.Red;

            int length = (int)(2 * gammaRange / gammaSample + 1);

            for (int i = 0; i < length; i++)
            {
                chart2D.ChartGroups[0].ChartData.SeriesList[0].X.Add(-1 * gammaRange + i * gammaSample);
                chart2D.ChartGroups[0].ChartData.SeriesList[0].Y.Add(data[i]);
            }

            chart2D.ChartArea.AxisX.Max = gammaRange;
            chart2D.ChartArea.AxisX.Min = -1 * gammaRange;

            return chart2D.GetImage();
        }

        #endregion

        #region 色品坐标

        string[][] dataCIE;

        PointPairList pplCIE1931 = new PointPairList();

        LineItem litCIE1931;

        private void readCIE(string fileName)
        {
            if (!File.Exists(fileName))
            {
                return;
            }

            FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read);

            if (fileStream == null)
            {
                return;
            }

            StreamReader streamReader = new StreamReader(fileStream);

            int index = 0;
            dataCIE = new string[80][];

            try
            {
                while (!streamReader.EndOfStream)
                {
                    string str = "";
                    str = streamReader.ReadLine();
                    string[] temp = new string[2];
                    temp = str.Split("	".ToCharArray());
                    dataCIE[index] = temp;
                    index++;
                }
            }
            catch { }
            finally
            {
                streamReader.Close();
                fileStream.Close();
            }
        }

        private void drawCIE(ZedGraphControl zed, string fileName)
        {
            zed.GraphPane.CurveList.Clear();

            zed.GraphPane.Chart.Fill = new ZedGraph.Fill(Color.White);
            zed.IsShowContextMenu = false; // 设置右键功能选项
            zed.IsShowPointValues = true;
            zed.PointValueFormat = "#0.0000";
            zed.GraphPane.Title.Text = "";

            zed.GraphPane.XAxis.Title.Text = "x";
            zed.GraphPane.XAxis.MajorGrid.IsVisible = true;
            zed.GraphPane.XAxis.Scale.Max = 0.8f;
            zed.GraphPane.XAxis.MajorGrid.PenWidth = 1f;

            zed.GraphPane.YAxis.Title.Text = "y";
            zed.GraphPane.YAxis.MajorGrid.IsVisible = true;
            zed.GraphPane.YAxis.Scale.Max = 0.9f;
            zed.GraphPane.YAxis.MajorGrid.PenWidth = 1f;

            readCIE(fileName);

            PointPairList pplList = new PointPairList();
            for (int i = 0; i < dataCIE.Length; i++)
            {
                double x = double.Parse(dataCIE[i][0].ToString());
                double y = double.Parse(dataCIE[i][1].ToString());
                pplList.Add(x, y);
            }
            pplList.Add(double.Parse(dataCIE[0][0].ToString()), double.Parse(dataCIE[0][1].ToString()));
            pplList.Add(double.Parse(dataCIE[79][0].ToString()), double.Parse(dataCIE[79][1].ToString()));

            LineItem litLine = zed.GraphPane.AddCurve("", pplList, Color.Blue, SymbolType.None);

            zed.AxisChange();
            zed.Refresh();
        }

        public Image PrintCIE(string fileName, double[] x, double[] y)
        {
            ZedGraphControl zedPolar= new ZedGraphControl();
            zedPolar.Width = 600;
            zedPolar.Height = 600;

            drawCIE(zedPolar, fileName);

            pplCIE1931.Clear();

            for (int i = 0; i < x.Length; i++)
            {
                pplCIE1931.Add(x[i], y[i]);
            }

            litCIE1931 = zedPolar.GraphPane.AddCurve("", pplCIE1931, Color.Red, SymbolType.XCross);

            litCIE1931.Line.IsVisible = false;

            zedPolar.Refresh();

            return zedPolar.GetImage();
        }

        #endregion
    }
}
